var Edit = {
		data: {},
		modelPath: "/templateParam"
}

Edit.save = function(){
	Edit.collectData();
	var ajax = new $ax(Base.ctxPath + Edit.modelPath+"/save", function(data){
		Tip.success("操作成功!");
		window.parent.Index.table.refresh();
		Edit.close();
	},function(data){
		Tip.error("操作失败!" + data.responseJSON.message + "!");
		setTimeout(function(){
			$("#submitBtn").removeAttr("disabled");
		},200); 
	});
	ajax.set(Edit.data);
	ajax.start();
}
Edit.submit = function(){
	Tip.confirm("确认提交？", function(){
		Edit.collectData();
		var ajax = new $ax(Base.ctxPath + Edit.modelPath+"/submit", function(data){
			Tip.success("操作成功!");
			window.parent.Index.table.refresh();
			Edit.close();
		},function(data){
			Tip.error("操作失败!" + data.responseJSON.message + "!");
			setTimeout(function(){
				$("#submitBtn").removeAttr("disabled");
			},200); 
		});
		ajax.set(Edit.data);
		ajax.start();
	});
}

Edit.close = function () {
	window.parent.layer.close(window.parent.Index.layerIndex);
};

Edit.collectData = function () {
	$(".form-control").each(function(i,v){ 
		Edit.data[v.id] = v.value;
	})
//	var html = $('.summernote').summernote('code').replace(/<p><br><\/p>/g,'');
//	Edit.data['htmlText'] = html;
};

Edit.clearData = function() {
	$(".form-control").each(function(i,v){ 
		$("#"+v.id).val("");
	})
}


Edit.tryExec =  function(){
	var editPage = layer.open({
		type : 2,
		title : 'html解析',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '100%', '100%' ],
		content : 'https://www.runoob.com/try/try.php?filename=tryhtml_intro'  // iframe的url
	});
	this.layerIndex = index;;
}

$(function(){
	//表单校验
	$("#submitForm").validate({
		rules: {
			channel: "required",
			fundModel: "required",
		}, 
		messages: {
		},
		submitHandler:function(form){
			Edit.submit();
		}
	});
	
	$("#saveBtn").on("click", function(){
		Edit.save();
	});
	$("#tryExecBtn").on("click", function(){
		Edit.tryExec();
	});
	
});
